const express = require('express');
const router = express.Router();

const uuid = require('node-uuid');

const sql = require('../sql/index');
const banner = require('../sql/col/Banner');


router.get('/', (req,res,next) =>{
    sql.find(banner,{},{_id:0}).then(data => {
        res.render('banner', {data});
    }) 
});

router.get('/add', (req,res,next) =>{
    res.render('banner_add');
});

router.post('/addAction', (req,res,next) =>{
    const { href, alt, bannerimg } = req.body;
    const bannerid = 'banner_' + uuid.v1();
    sql.insert(banner,{bannerid,href, bannerimg,alt}).then(()=>{
        res.send('success');
    }) 
})

module.exports = router;